#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int deleteAndEarn(vector<int>& nums) {
        vector<int> as(10001);
        for (int i = 0; i < nums.size(); i++)
        {
            as[nums[i]] += nums[i];
        }
        vector<int> p1(as.size());
        p1[0] = as[0];
        auto p2 = p1;
        for (int i = 1; i < as.size(); i++)
        {
            p1[i] = p2[i - 1] + as[i];
            p2[i] = max(p2[i - 1], p1[i - 1]);
        }
        return max(p1[as.size() - 1], p2[as.size() - 1]);
    }
};